package com.csgc.camera.widget.mask

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.get

import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.events.ChangeRemarkStatus
import com.csgc.camera.events.MaskDataStyleEvent
import com.csgc.camera.events.MaskEditDateEvent
import com.csgc.camera.events.MaskLocationEvent
import com.csgc.camera.events.MaskUpdateContent
import com.csgc.camera.events.TimeChangeEvent
import com.csgc.camera.util.TimeUtil
import com.csgc.camera.widget.dialog.CustomMaskHandle
import com.cysd.spsyxj.R

import com.drake.channel.receiveEvent
import com.drake.channel.receiveEventHandler
import com.elvishew.xlog.XLog
import kotlinx.coroutines.Job

class MaskKaoQin: MaskBase {



    constructor(context: Context?,id:Int) : super(context,null){

        if(id == 0){
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_1, this, true)
        }else if (id == 1){
            dateStyle = "yyyy/MM/dd"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_2, this, true)
        }else if (id == 2){
            customTextColor = ContextCompat.getColor(context!!,R.color.title_color)
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_3, this, true)
        }else if (id == 3){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_4, this, true)
        }else if (id == 4){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_5, this, true)
        }else if (id == 5){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_6, this, true)
        }else if (id == 6){
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_7, this, true)
        }else if (id == 7){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_8, this, true)
        }
        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView()

    }

    private fun initView(){
        location = findViewById(R.id.tv_kao_qin_location)
        remark = findViewById(R.id.tv_kao_qin_remark)
        date = findViewById(R.id.tv_kao_qin_date)
        week = findViewById(R.id.tv_kao_qin_week)
        time = findViewById(R.id.tv_kao_qin_time)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)

        location?.text = MaskConfig.maskLocation

        changeDateTime()


        MaskConfig.maskMap[0]?.forEach {
            if(it.title == "备注"){
                remark?.text = "${it.title}:${it.content}"
                remark?.visibility = if(it.isOpen) View.VISIBLE else View.GONE
            }
        }

        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(customTextColor)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }
    }

}